Calculate the number of odd bits in byteΒΆ

a = 7
num_bits = 0
while a:
    num_bits += a & 1
    a = a >> 1
print(num_bits)

Output:

3